﻿{include file='pub/header'/}
<title>商品列表</title>
</head>
<body class="pos-r">
<nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
                                       href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i></a></nav>
<div>
    <div class="page-container">
        <div class="text-c">
            <form action="" method="get">
                商品名称：<input type="text" name="name" id="" placeholder=" 商品名称" style="width:250px" class="input-text">
                商品货号：<input type="text" name="gno" id="" placeholder=" 商品货号" style="width:250px" class="input-text">
                <button class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜商品
                </button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius">
                    <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
                </a>
                <a class="btn btn-primary radius" onclick="updateImage()" href="javascript:;">
                    <i class="Hui-iconfont Hui-iconfont-huanyipi"></i> 更新商品图片
                </a>
            </span>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
               href="javascript:location.replace(location.href);" title="刷新">
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="40"><input name="" type="checkbox" value=""></th>
                    <th width="40">ID</th>
                    <th width="40">商品货号</th>
                    <th width="60">缩略图</th>
                    <th width="100">产品名称</th>
                    <th width="100">单价</th>
                    <th width="60">单位</th>
                    <th width="60">规格</th>
                    <th width="60">是否是组合商品</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $goods_list as $good}
                <tr class="text-c va-m">
                    <td><input name="id" type="checkbox" value="{$good.id}"></td>
                    <td>{$good.id}</td>
                    <td>{$good.gno}</td>
                    <td>
                        <a onClick="picture_show('查看图片', '{$good.img}')" data-src="" href="javascript:;">
                            <img width="60" class="product-thumb" src="{:explode(',', $good['img'])[0]}">
                        </a>
                    </td>
                    <td class="text-l">
                        {$good.name}
                    </td>
                    <td class="text-l">
                        {$good.sale_price}
                    </td>
                    <td class="text-l">
                        {$good.goodattr}
                    </td>
                    <td>
                        {$good.guige}
                    </td>
                    <td class="td-status">
                        {if condition="$good.combine_sta eq 1"}是
                        {else /}否
                        {/if}
                    </td>
                    <td class="td-manage">
                        <a style="text-decoration:none" class="ml-5"
                           onClick="changeStatus('{$good.id}', this)"
                           href="javascript:;" title="状态">
                            {if $good.is_live == 1}
                                下架
                            {else/}
                                上架
                            {/if}
                        </a>
                        <a style="text-decoration:none" class="ml-5"
                           onClick="product_edit('产品编辑','{:url(\'Products/productEdit\', [\'good_id\'=>$good.id])}')"
                           href="javascript:;" title="编辑">
                            <i class="Hui-iconfont">&#xe6df;编辑</i>
                        </a>
                        <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'{$good.id}')"
                           href="javascript:;" title="删除">
                            <i class="Hui-iconfont">&#xe6e2;删除</i>
                        </a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
</div>

{include file='pub/footer'/}
<script type="text/javascript">
    $('.table-sort').dataTable({
        "aaSorting": [[1, "asc"]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            {"orderable": false, "aTargets": [0, 8]}// 制定列不参与排序
        ]
    });

    /**
     * 更新商品图片
     */
    function updateImage(){
        layer.load();
        $.post("{:url('updateImage')}", null, function (res) {
            layer.closeAll();
            if(res.code == 1){
                layer.alert('更新成功');
            }else{
                layer.alert(res.msg);
            }
        });
    }
    /**
     * 上下架商品
     */
    function changeStatus(good_id, o){
        var status = $(o).html();
        if(status == '上架'){
            var code = 1;
        }else{
            var code = 0;
        }
        $.post("{:url('Products/changeStatus')}", {code:code, good_id:good_id}, function (res) {
            if(res.code == 1){
                if(code == 1){
                    $(o).html('下架');
                }else{
                    $(o).html('上架');
                }
                layer.msg('修改成功');
            }else{
                layer.msg('修改失败');
            }
        });
    }

    /*图片-查看*/
    function picture_show(title, url, id) {
        var imgsurl = url.split(',');
        var content = '';
        $.each(imgsurl, function (i, v) {
            content += "<img style='width: 120px; margin: 10px;' src='" + v + "'/>";
        });
        var index = layer.open({
            type: 1,
            title: title,
            content: content
        });
        layer.full(index);
    }

    /*产品-编辑*/
    function product_edit(title, url, id) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /*产品-删除*/
    function product_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.post("{:url('Products/delData')}", {idstr:id}, function (res) {
                if(res.code == 1){
                    layer.msg('删除成功');
                    $(obj).parents('tr').remove();
                }else{
                    layer.msg(res.msg);
                }
            });
        });
    }
    //删除选中产品
    function datadel() {
        var $ids = $("input[name='id']:checked");
        if($ids.length<1){
            layer.alert('请选中后在操作');
            return false;
        }
        var idarr = new Array();
        $.each($ids, function (i, v) {
            idarr.push($(v).val());
        });
        var idStr = idarr.toString();
        layer.confirm('确认删除选中项？', function () {
            $.post("{:url('Products/delData')}", {idstr:idStr}, function (res) {
                if(res.code == 1){
                    layer.msg('删除成功');
                    $ids.parents('tr').remove();
                }else{
                    layer.msg(res.msg);
                }
            });
        });
    }
</script>
</body>
</html>